from rest_framework import serializers
from rest_framework.permissions import IsAdminUser
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet

from goods.models import SKUImage, SKU
from meiduo_admin.serializers.images import SKUImageSerializer, SKUSerializer
from meiduo_admin.utils import PageNum


class ImageView(ModelViewSet):

    # 图片表增删查改
    # 指定序列化器
    serializer_class = SKUImageSerializer
    #指定数据的查询集
    queryset = SKUImage.objects.all()
    # 指定权限
    permission_classes = [IsAdminUser]
    # 指定分页器
    pagination_class = PageNum

    def simple(self,request):
        # 获取所有sku信息
        skus = SKU.objects.all()
        # 返回sku信息
        ser = SKUSerializer(skus,many=True)
        return Response(ser.data)


